<template>
  <div class="app-container" style="overflow: scroll">
    <div style="width: 1024px;margin: 0 auto">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" disabled>
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="上一个工作日" prop="cpgDatePre">
            <el-date-picker v-model="form.cpgDatePre" style="width: 100%;" type="date" value-format="yyyyMMdd" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="当前CPG日期" prop="cpgDate">
            <el-date-picker v-model="form.cpgDate" style="width: 100%;" type="date" value-format="yyyyMMdd" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="下一个工作日" prop="cpgDateNext">
            <el-date-picker v-model="form.cpgDateNext" style="width: 100%;" type="date" value-format="yyyyMMdd" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="未复核交易笔数" prop="count1">
            <el-input v-model="form.count1" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="未审核交易笔数" prop="count2">
            <el-input v-model="form.count2" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="未回执交易笔数" prop="count3">
            <el-input v-model="form.count3" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="来账未处理交易笔数" prop="count4">
            <el-input v-model="form.count4" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="行内排队交易笔数" prop="count5">
            <el-input v-model="form.count5" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="大额已发送未清算交易笔数" prop="count7">
            <el-input v-model="form.count7" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="小额轧差排队交易" prop="count9">
            <el-input v-model="form.count9" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="大额正发送交易笔数" prop="count10">
            <el-input v-model="form.count10" />
          </el-form-item>
        </el-col>
      </el-row>


      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="小额待打包交易笔数" prop="count11">
            <el-input v-model="form.count11" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="小额正发送交易笔数" prop="count12">
            <el-input v-model="form.count12" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="switch2()">切换到上一个工作日</el-button>
        <el-button type="primary" @click="switch1()">切换到下一个工作日</el-button>
      </div>
    </div>
    </div>

</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";
import BankBranchDialog from "@/views/components/BankBranchDialog";
import { getBankInfByBankCode } from "@/api/cnaps/common/bankInfo";
import HtAmountInput from "@/views/components/HtAmountInput";
import { pvpSettlementApplyInformationEntrySave } from "@/api/cnaps/hvps/143";
import { page, switch1, switch2, update, update2 } from "@/api/cnaps/date/cpgdate";

export default {
  name: "cpgdateChange",
  mixins: [listPageMixin],
  components: { HtAmountInput, BankBranchDialog },

  created() {
    page().then((res) => {
      this.form = res.result;
    });
  },
  watch: {

  },
  data() {
    return {
      // 录入参数
      form: {

      },

      loading: false,
      //
      searchFormDictList: [],

      rules: {

      },

    };
  },
  mounted() {

  },
  methods: {

    switch1(){
      let num =Number(this.form.count1)+Number(this.form.count2)+Number(this.form.count3)+Number(this.form.count4)
        +Number(this.form.count5)+Number(this.form.count7)+Number(this.form.count9)+Number(this.form.count10)
        +Number(this.form.count11)+Number(this.form.count12);
      if (num > 0) {
        this.$confirm("当天还有 " + num + " 笔交易未完成，是否要切换工作日")
          .then((_) => {
            switch1(this.form).then((result) => {
              if (result.code === "S") {
                this.msgSuccess("日期切换成功");
                if (result.result.num === 0) {
                  this.update();
                }
              } else {
               this.msgError("日期切换失败");
              }
            })
            done();
          })
          .catch((_) => {});

      }else{
        this.$confirm("是否要切换工作日")
          .then((_) => {
            switch1(this.form).then((result) => {
              if (result.code === "S") {
                this.msgSuccess("日期切换成功");
                if (result.result.num === 0) {
                  this.update();
                }
              } else {
                this.msgError("日期切换失败");
              }
            })
            done();
          })
          .catch((_) => {});
      }
    },

    switch2(){
      let num =Number(this.form.count1)+Number(this.form.count2)+Number(this.form.count3)+Number(this.form.count4)
        +Number(this.form.count5)+Number(this.form.count7)+Number(this.form.count9)+Number(this.form.count10)
        +Number(this.form.count11)+Number(this.form.count12);
      if (num > 0) {
        this.$confirm("当天还有 " + num + " 笔交易未完成，是否要切换工作日")
          .then((_) => {
            switch2(this.form).then((result) => {
              if (result.code === "S") {
                this.msgSuccess("日期切换成功");
                if (result.result.num === 0) {
                  this.update2();
                }
              } else {
                this.msgError("日期切换失败");
              }
            })
            done();
          })
          .catch((_) => {});

      }else{
        this.$confirm("是否要切换工作日")
          .then((_) => {
            switch2(this.form).then((result) => {
              if (result.code === "S") {
                this.msgSuccess("日期切换成功");
                if (result.result.num === 0) {
                  this.update2();
                }
                // else if(result.result.result.num === 1) {
                //     $.modal.confirm(result.result.errInfo,function() {
                //         update();
                //     });
                // }
              } else {
                this.msgError("日期切换失败");
              }
            })
            done();
          })
          .catch((_) => {});
      }
    },

    update(){
      update(this.form).then((result)=>{
          this.$set(this,"form",result.result)
      })
    },

    update2(){
      update2(this.form).then((result)=>{
        this.$set(this,"form",result.result)
      })
    },




  },
};
</script>
